﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using InternalManagementSystem.DAO;
using InternalManagementSystem.DAO.Models;

/// <summary>
///PermissionHelper 的摘要说明
/// </summary>
public class PermissionHelper
{
	public PermissionHelper()
	{
		//
		//TODO: 在此处添加构造函数逻辑
		//
	}

    /*
     
安全员只管扣分
班组安全员管理公司的违章记录
然后员工这些也全是管理员录入的，导入的

公司分配也全给管理员做，这样简单多了

     
     */

    public Permission GetPermission(int userid)
    {
        StaffDAO dao = new StaffDAO();
        Staff user = dao.LoadUser(userid);
        return GetPermission((EUserRole)user.RoleID);
    }

    public Permission GetPermission(EUserRole role)
    {
        Permission permission = new Permission();
        permission.EUserRole = role;

        switch (role)
        {
            case EUserRole.superadmin://超级管理员 
                permission.IsUserEdit = true;
                permission.IsCompanyEdit = true;
                permission.IsAutoRechargEdit = true;
                permission.IsUserRoleEdit = true;
                permission.IsViolationNoticeCreate = true;
                permission.IsViolationNoticeTimeEdit = true;
                permission.IsViolationNoticeEdit = true;
                permission.IsUserTypeEdit = true;
                permission.IsDoAssign = true;
                
                break;

            case EUserRole.admin: //安全员可以对违章人员扣分、处罚
                permission.IsViolationNoticeCreate = true;
                permission.IsViolationNoticeTimeEdit = true;
                permission.IsDeductOperate = true;
                
                break;

            case EUserRole.leader: //班组安全员可以录入违章通知
                permission.IsViolationNoticeCreate = true;
                break;

            case EUserRole.user: //班组员工只能查询
                break;

            default: break;

        }
        return permission;

    }
}

public class Permission
{
    /// <summary>
    /// 1.	可以自由编辑员工的权限身份
    /// </summary>
    private bool isUserRoleEdit = false;
    public bool IsUserRoleEdit
    {
        get { return isUserRoleEdit; }
        set { isUserRoleEdit = value; }
    }

    /// <summary>
    /// 超级管理员可以对“类型”进行增加/删除，并指定该类型的警戒线值
    /// </summary>
    private bool isUserTypeEdit = false;
    public bool IsUserTypeEdit
    {
        get { return isUserTypeEdit; }
        set { isUserTypeEdit = value; }
    }

    /// <summary>
    /// 2.	对公司部门组织进行自由增加和删除
    /// </summary>
    private bool isCompanyEdit = false;
    public bool IsCompanyEdit
    {
        get { return isCompanyEdit; }
        set { isCompanyEdit = value; }
    }

    private bool isDoAssign = false;
    public bool IsDoAssign
    {
        get { return isDoAssign; }
        set { isDoAssign = value; }
    }

    /// <summary>
    /// 3.	对公司员工信息自由增加和删除
    /// </summary>
    private bool isUserEdit = false;
    public bool IsUserEdit
    {
        get { return isUserEdit; }
        set { isUserEdit = value; }
    }

    /// <summary>
    /// 4.	对公司员工的违章违纪情况进行记录
    /// </summary>
    private bool isViolationNoticeCreate = false;
    public bool IsViolationNoticeCreate
    {
        get { return isViolationNoticeCreate; }
        set { isViolationNoticeCreate = value; }
    }
    /// <summary>
    /// 4.	对公司员工的违章违纪情况进行记录
    /// </summary>
    private bool isViolationNoticeEdit = false;
    public bool IsViolationNoticeEdit
    {
        get { return isViolationNoticeEdit; }
        set { isViolationNoticeEdit = value; }
    }
    /// <summary>
    /// 5.	可以设定违章违纪记录统计的时间段信息
    /// </summary>
    private bool isViolationNoticeTimeEdit = false;
    public bool IsViolationNoticeTimeEdit
    {
        get { return isViolationNoticeTimeEdit; }
        set { isViolationNoticeTimeEdit = value; }
    }

    /// <summary>
    /// 6.	系统能够在超过设定的时间段后自动充值违章违纪统计，重新计算警戒线。
    /// </summary>
    private bool isAutoRechargEdit = false;
    public bool IsAutoRechargEdit
    {
        get { return isAutoRechargEdit; }
        set { isAutoRechargEdit = value; }
    }

    /// <summary>
    /// 是否能进行扣分操作
    /// </summary>
    private bool isDeductOperate = false;
    public bool IsDeductOperate 
    {
        get { return isDeductOperate; }
        set { isDeductOperate = value; }
    }

    /// <summary>
    /// 7.	对公司员工违章违纪信息自由浏览
    /// </summary>
    public bool HasBrowsePermission 
    {
        get { return true; }
    }

    public EUserRole EUserRole { set; get; }

    public int UserID { set; get; }

    public string UserName { set; get; }
}

public enum EUserRole
{
    superadmin = 1,
    admin,
    leader,
    user
}
